package org.hyl.javabase.集合扩展;

public class demo3 {
	// 思路 老鼠 ，管子 ，金币
	
	public static  void main(String[] arg) {
		fun();
	}
	public static  void fun() {
		channel c1 = new channel('c');
		channel c2 = new channel('b');
		channel c3 = new channel('a');
		c1.setNext(c2);
		c2.setNext(c3);
	//	c1.setNext(new channel('b').setNext(new channel('c')));
		//从小到大 a》b》c
		mouse m=new mouse('a');
		System.out.println(go(m, c1));
	}
	public static int go(mouse m, channel c) {
		if (m.type < c.type) {	//b<c
			m.take(c.money);
			return go(m, c.next);
		} else if (m.type == c.type) {
			m.take(c.money);
			return m.getall();
		} else
			return 0;
	}
}

class mouse {
	char type = 'a';
	int money = 0;
	public mouse(char type) {
		this.type = type;
		}
	public void take(int money) {
		this.money += money;
	}
	public int getall() {
		return money;
	}
}

class channel {
	char type = 'a';
	channel next = null;
	int money = 1;
	public channel setNext(channel nc) {
		next = nc;
		return this;
	}
	public channel(char type) {
		this.type = type;
		switch (type) {
		case 'a':
			money = 1;
			break;
		case 'b':
			money = 5;
			break;
		default:
			money = 10;
		}

	}
}
